package com.cn.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.cn.pojo.FileInfo;
public interface FileDao {
	@Insert("insert into fileinfo(fileName,downloadSum,url,type) value(#{fileName},0,#{url},#{type})")
	boolean addFile(@Param("fileName")String fileName,@Param("url")String url,@Param("type")Integer type);
	@Select("select fileinfo.id,fileinfo.fileName,fileinfo.downloadSum,fileinfo.url,typeinfo.type from fileinfo left join typeinfo on typeinfo.id=fileinfo.type")
	List<Map<String,Object>> consultFile();
	@Select("select id,fileName,downloadSum,url from fileinfo where type=#{type}")
	List<FileInfo> consultFileByTypeId(@Param("type")Integer typeId);
	@Select("select id,fileName,url from fileinfo where id=#{id}")
	FileInfo consultFileById(@Param("id")Integer id);
	@Delete("delete from fileinfo where id=#{id}")
	boolean deleteFile(@Param("id")Integer id);
	@Update("update fileinfo set downloadSum=downloadSum+1 where id=#{id}")
	void updateDownLoadSum(@Param("id") Integer id);
}
